package com.example.pingxue.repository;

import com.example.pingxue.entity.Student;
import com.example.pingxue.entity.Selection;
import com.example.pingxue.entity.TClass;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface SelectionRepository extends JpaRepository<Selection, Long> {
    Optional<Selection> findByStudentAndClazz(Student student, TClass clazz);

    @Query("SELECT s FROM Selection s JOIN FETCH s.student WHERE s.clazz.id = :classId")
    List<Selection> findByClassIdWithStudents(Long classId);
}
